package mpo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Kategoria {

    private int id;
    private String nazwa;
    private Date dataWaznosci;
    private String pesel;
    private Pracownik owner;

    public Kategoria(Pracownik owner, String nazwa, String dataWaznosciDoParsowania) {
        this.owner = owner;
        this.nazwa = nazwa;
        try {
            this.dataWaznosci = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(dataWaznosciDoParsowania);
        } catch (Exception e) {
            this.dataWaznosci = null;
        }
        pesel = owner.getPesel();
    }

    public Kategoria(int id, String nazwa, String dataWaznosciDoParsowania, Pracownik owner) {
        this.id = id;
        this.nazwa = nazwa;
        try {
            this.dataWaznosci = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(dataWaznosciDoParsowania);
        } catch (Exception e) {
            this.dataWaznosci = null;
        }
        this.owner = owner;
        this.pesel = owner.getPesel();
    }

    public Kategoria(int id, String nazwa, String dataWaznosciDoParsowania) {
        this.id = id;
        this.nazwa = nazwa;
        try {
            this.dataWaznosci = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(dataWaznosciDoParsowania);
        } catch (Exception e) {
            this.dataWaznosci = null;
        }
    }

    public String getNazwa() {
        return nazwa;
    }

    public void setNazwa(String nazwa) {
        this.nazwa = nazwa;
    }

    public Date getDataWaznosci() {
        return dataWaznosci;
    }

    public String getDataWaznosciViaString() {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String date = sdf.format(dataWaznosci);
            return date;
        } catch (Exception e) {
            return null;
        }
    }

    public void setDataWaznosci(Date dataWaznosci) {
        this.dataWaznosci = dataWaznosci;
    }

    public void setDataWaznosciViaString(String dataS) {
        try {
            this.dataWaznosci = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(dataS);
        } catch (Exception e) {
            this.dataWaznosci = null;
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int idInBase) {
        this.id = idInBase;
    }

    public String getOwnerPesel() {
        try {
            String pesel = getOwner().getPesel();
            return pesel;
        } catch (Exception e) {
            return null;
        }
    }

    public Pracownik getOwner() {
        return owner;
    }

    public void setOwner(Pracownik owner) {
        this.owner = owner;
    }

    public String getPesel() {
        return pesel;
    }

    public void setPesel(String pesel) {
        this.pesel = pesel;
    }

    @Override
    public String toString() {
        return "Kategoria{" + "id=" + id + ", nazwa=" + nazwa + ", dataWaznosci=" + dataWaznosci + ", pesel=" + pesel + '}';
    }

}
